export type ProjectStatus = '未开始' | '未达标' | '已达标'

export interface ContractRequirement {
  id: number
  project_id: number
  requirement_type: string
  target_quantity: number
  quality_requirements: {
    as?: number | null
    da?: number | null
    count?: number | null
    dofollow?: boolean | null
  }
  additional_notes: string
  status: 'PENDING' | 'COMPLETED'
  created_time: string
  updated_time: string
}

export interface ProjectItem {
  id: number
  name: string
  quantity: number | null
  price: number
  details: {
    as: number | null
    da: number | null
    count: number | null
    dofollow: boolean | null
  }
  status: 'PENDING' | 'COMPLETED'
}

export interface Project {
  id: number
  project_code: string
  customer_name: string
  customer_domain: string
  project_type: string
  status: ProjectStatus
  contract_terms: {
    img?: string | null
    text?: string
    extra_note?: string
    amount?: number
  }
  start_date: string | null
  end_date: string | null
  customer_manager: string | null
  created_time: string
  updated_time: string
  contract_requirements?: ContractRequirement[] // 合同要求
  contract_amount?: number // 合同金额
  contract_count?: number  // 合同条数
  items?: ProjectItem[]    // 项目条目
}

export interface Stats {
  total: number
  未达标: number
  已达标: number
  未开始: number
  逾期: number
}

// 项目进度相关类型定义
export interface ProjectProgressInfo {
  id: number
  project_code: string
  project_name: string
  status: ProjectStatus
  customer_manager: string | null
  project_type: string
  start_date: string
  end_date: string
}

export interface ProgressSnapshotInfo {
  snapshot_date: string
  created_time: string
}

export interface TypeProgressData {
  [key: string]: {
    quality_check: any | null
    completion_rate: number
    target_quantity: number
    completed_quantity: number
  }
}

export interface IndexStatus {
  indexed: number
  pending: number
  index_rate: number
  not_indexed: number
}

export interface DADistribution {
  da_0_30: number
  da_30_50: number
  da_50_70: number
  da_70_plus: number
}

export interface QualityMetrics {
  index_status: IndexStatus
  da_distribution: DADistribution
  total_backlinks: number
  avg_quality_score: number
}

export interface AmountUsage {
  total_price: number
  freeze_price: number
  submit_price: number
  confirm_price: number
  remaining_price: number
}

export interface ProjectProgressData {
  project_info: ProjectProgressInfo
  snapshot_info: ProgressSnapshotInfo
  type_progress_data: TypeProgressData
  quality_metrics: QualityMetrics
  amount_usage: AmountUsage
}

export interface ProjectProgressResponse {
  code: number
  message: string
  data: ProjectProgressData
  timestamp: number
}

// 项目时间线相关类型定义
export interface TypeProgressDetail {
  [key: string]: {
    quality_check: any | null
    completion_rate: number
    target_quantity: number
    completed_quantity: number
  }
}

export interface TypeSummary {
  total_types: number
  completed_types: number
  in_progress_types: number
  not_started_types: number
}

export interface TimelineDataPoint {
  date: string
  cumulative_completed: number
  cumulative_target: number
  cumulative_completion_rate: number
  type_progress_detail: TypeProgressDetail
  quality_metrics: QualityMetrics
  type_summary: TypeSummary
  daily_increment: number
  planned_completion_rate: number
  variance: number
}

export interface TrendAnalysis {
  completion_trend: 'IMPROVING' | 'DECLINING' | 'STABLE'
  avg_daily_increment: number
  projected_completion_date: string
  risk_level: 'LOW' | 'MEDIUM' | 'HIGH'
  recommendations: string[]
}

export interface DateRange {
  start_date: string
  end_date: string
}

export interface ProjectTimelineData {
  project_id: number
  period: 'daily' | 'weekly' | 'monthly'
  date_range: DateRange
  timeline_data: TimelineDataPoint[]
  trend_analysis: TrendAnalysis
}

export interface ProjectTimelineResponse {
  code: number
  message: string
  data: ProjectTimelineData
  timestamp: number
}